﻿using ICUP13.Management;
using ICUP13.States;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using ICUP13.Texture;

namespace ICUP13
{
    public class MainGame : Game
    {
        // Data Members
        private static GraphicsDeviceManager _graphics;
        private static SpriteBatch _spriteBatch;

        // Public Static Properties
        public static GraphicsDevice Device
        {
            get { return _graphics.GraphicsDevice; }
        }
        public static Rectangle ClientRect
        {
            get { return _graphics.GraphicsDevice.Viewport.TitleSafeArea; }
        }
        public static SpriteBatch Batch
        {
            get { return _spriteBatch; }
        }

        // Constructors
        public MainGame()
        {
            this.IsMouseVisible = true;
            _graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            StateMachine.Initalize();
        }

        // Game Methods
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            TextureManager.GetInstance().LoadTextures(Content);
            StateMachine.ChangeStateQueue(new SplashScreenState());
        }
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }
        protected override void Update(GameTime gameTime)
        {
            StateMachine.CheckQueue();
            // TODO: Add your update logic here
            if (StateMachine.StateInput((float)gameTime.ElapsedGameTime.TotalSeconds, (float)gameTime.TotalGameTime.TotalSeconds, 0) == false)
                this.Exit();

            StateMachine.StateUpdate((float)gameTime.ElapsedGameTime.TotalSeconds, (float)gameTime.TotalGameTime.TotalSeconds, 0);

            base.Update(gameTime);
        }
        protected override void Draw(GameTime gameTime)
        {
            Batch.Begin();
            StateMachine.StateDraw((float)gameTime.ElapsedGameTime.TotalSeconds, (float)gameTime.TotalGameTime.TotalSeconds, 0);
            Batch.End();
            base.Draw(gameTime);
        }
    }
}
